package main.Q2301_2400;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Q2351_2360 {
    public static void main(String[] args) {
        System.out.println("Question2351：");
        System.out.println("Question2352：相等行列对");
        System.out.println("Question2353：");
        System.out.println("Question2354：");
        System.out.println("Question2355：");
        System.out.println("Question2356：");
        System.out.println("Question2357：根据模式串构造最小数字");
        System.out.println("Question2358：");
        System.out.println("Question2359：");
        System.out.println("Question2360：");
    }
}

class Question2352 {
    public int equalPairs(int[][] grid) {
        int result = 0;
        List<String> row = new ArrayList<>(), col = new ArrayList<>();
        for (int i = 0; i < grid.length; i++) {
            StringBuffer rowStr = new StringBuffer(), colStr = new StringBuffer();
            for (int j = 0; j < grid.length; j++) {
                rowStr.append(grid[i][j]);
                colStr.append(grid[j][i]);
                colStr.append("-");
                rowStr.append("-");
            }
            row.add(rowStr.toString());
            col.add(colStr.toString());
        }
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid.length; j++) {
                if (row.get(i).equals(col.get(j))) result++;
            }
        }
        return result;
    }
}

class Question2357 {
    public String smallestNumber(String pattern) {
        Stack<Integer> stack = new Stack<>();
        StringBuilder result = new StringBuilder();
        int num = 1;
        for (int i = 0; i < pattern.length(); i++) {
            if (pattern.charAt(i) == 'D') {
                // 如果为下降，则将当前数字压入栈中
                stack.push(num);
            } else if (pattern.charAt(i) == 'I') {
                result.append(num);
                while (!stack.isEmpty()) {
                    result.append(stack.pop());
                }
            }
            num++;
        }
        stack.add(num);
        while (!stack.isEmpty()) {
            result.append(stack.pop());
        }
        return result.toString();
    }
}